<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <title>test my-promise</title>
</head>
<body>
  <script src='./index.es6.js'></script>
  <!-- <script src='./index.js'></script> -->
  <script>
    const p = new MyPromise((resolve, reject) => {
      setTimeout(() => {
        resolve('resolve a promise');
        // reject('reject a promise');
      }, 2 * 1000);
    });
    // resolve参数是MyPromise实例
    new MyPromise((resolve, reject) => {
      resolve(p);
      // reject('rejected');
    }).then(res => {
      console.log('>>> res', res);
      return 'res1';
    }, err => {
      console.log('>>> err', err);
      return 'err1';
    }).then(res2 => {
      console.log('>>> res2', res2);
    }, err2 => {
      console.log('>>> err2', err2);
    }).finally(() => {
      console.log('>>> finally')
    });
    
    // then第一个方法返回的是MyPromise实例
    /*new MyPromise((resolve, reject) => {
      resolve('resolved');
      // reject('rejected');
    }).then(res => {
      console.log('>>> res', res);
      return p;
    }, err => {
      console.log('>>> err', err);
      return 'err1';
    }).then(res2 => {
      console.log('>>> res2', res2);
    }, err2 => {
      console.log('>>> err2', err2);
    });*/
  </script>
</body>
</html>